import React from "react"

import http from "../helper/request"
import {
	IBanklistResponse,
	IPersonValueItemResponse,
	IPersonValueQueryParams,
	IPersonValueReportType,
	ISystemValidateKeyTypeResponse
} from "./types"

const useApi = () => {
	const { useState } = React
	const [loading, setLoading] = useState(false)

	async function generalHttp<T>(url: string, body: object | undefined) {
		setLoading(true)
		const ret = await http.post<T>(url, body)
		setLoading(false)
		return ret
	}

	const updateBankList = async (body: object | undefined) => {
		const ret = await generalHttp("/bankManage/query", body)
		return ret
	}

	const banklist = async (body: object | undefined) => {
		const ret = await generalHttp<IBanklistResponse>("/bankManage/query", body)
		return ret
	}

	const deleteBankList = async (body: object | undefined) => {
		const ret = await generalHttp("/bankManage/delete", body)
		return ret
	}

	const addBankList = async (body: object | undefined) => {
		const ret = await generalHttp("/bankManage/add", body)
		return ret
	}

	const editBankList = async (body: object | undefined) => {
		const ret = await generalHttp("/bankManage/update", body)
		return ret
	}
	const imgUpload = async (body: object | undefined) => {
		const ret = await generalHttp("/materialImage/upload", body)
		return ret
	}

	const getPersonListModules = async (body: object | undefined) => {
		const ret = await generalHttp("/person/listModules", body)
		return ret
	}
	const getSystemList = async (body: object | undefined) => {
		const ret = await generalHttp("/person/list", body)
		return ret
	}
	const editSystemList = async (body: object | undefined) => {
		const ret = await generalHttp("/person/update", body)
		return ret
	}
	const queryMenuListApi = async (body: object | undefined) => {
		const ret = await generalHttp("/system/menu/quer4Page", body)
		return ret
	}

	const addMenuApi = async (body: object | undefined) => {
		const ret = await generalHttp("/system/menu/addSubMenu", body)
		return ret
	}
	const editMenuApi = async (body: object | undefined) => {
		const ret = await generalHttp("/system/menu/update", body)
		return ret
	}
	const delMenuApi = async (body: object | undefined) => {
		const ret = await generalHttp("/system/menu/delete", body)
		return ret
	}
	const getDicList = async (body: object | undefined) => {
		const ret = await generalHttp("/person/getValue", body)
		return ret
	}

	const getConfig = async (body: object | undefined) => {
		const ret = await generalHttp("/system/userLoginLog/query4Page", body)
		return ret
	}

	const getClubParam = async (body: object | undefined) => {
		const ret = await generalHttp("/club/queryClubParam", body)
		return ret
	}
	const getClubParamUpdate = async (body: object | undefined) => {
		const ret = await generalHttp("club/addOrUpdateClubParam", body)
		return ret
	}
	const queryDictModuleList = async (body: object | undefined) => {
		const ret = await generalHttp("/system/kvConfig/loadModuleList", body)
		return ret
	}

	const updateDictConfig = async (body: object | undefined) => {
		const ret = await generalHttp("/system/kvConfig/update", body)
		return ret
	}
	const getAppVersion = async (body: object | undefined) => {
		const ret = await generalHttp("/system/appVersionConfig/page4Page", body)
		return ret
	}

	const addAppVersion = async (body: object | undefined) => {
		const ret = await generalHttp("/system/appVersionConfig/add", body)
		return ret
	}

	const editAppVersion = async (body: object | undefined) => {
		const ret = await generalHttp("/system/appVersionConfig/update", body)
		return ret
	}

	const openAppVersion = async (body: object | undefined) => {
		const ret = await generalHttp("/system/appVersionConfig/onOff", body)
		return ret
	}
	const getDomain = async (body: object | undefined) => {
		const ret = await generalHttp("/system/configDomain/query4Page", body)
		return ret
	}

	const addDomain = async (body: object | undefined) => {
		const ret = await generalHttp("/system/configDomain/add", body)
		return ret
	}

	const editDomain = async (body: object | undefined) => {
		const ret = await generalHttp("/system/configDomain/update", body)
		return ret
	}

	const delDomain = async (body: object | undefined) => {
		const ret = await generalHttp("/system/configDomain/delete", body)
		return ret
	}

	const getkvconfigQueryList = async (body: IPersonValueQueryParams) =>
		await generalHttp<IPersonValueReportType<IPersonValueItemResponse>>("/person/getValue", body)
	const seaMoonValidate = async (body: object | undefined) => await generalHttp("/seaMoonShield/seaMoonShieldVer", body)

	const getSystemValidateKeyType = async (body?: object | undefined) =>
		await generalHttp<ISystemValidateKeyTypeResponse>("/dict/getVerifyCodeType", body)

	return {
		delDomain,
		getDomain,
		addDomain,
		editDomain,
		openAppVersion,
		addAppVersion,
		editAppVersion,
		getAppVersion,
		updateDictConfig,
		queryDictModuleList,
		getDicList,
		getConfig,
		getClubParam,
		getClubParamUpdate,
		editBankList,
		editSystemList,
		getSystemList,
		delMenuApi,
		editMenuApi,
		addMenuApi,
		queryMenuListApi,
		getPersonListModules,
		imgUpload,
		banklist,
		deleteBankList,
		addBankList,
		generalHttp,
		updateBankList,
		getkvconfigQueryList,
		seaMoonValidate,
		getSystemValidateKeyType,
		loading
	}
}

export default useApi
